package com.mazaiting.common.core.ex.runtime;

import com.mazaiting.common.core.domain.result.ResultCode;

/**
 * runtime 异常基类
 *
 * @author mazaiting
 * @create_time 2022/9/30 23:35
 */
public class BaseRuntimeException extends RuntimeException {

    /**
     * 状态码
     */
    private final Integer code;

    /**
     * 错误消息
     */
    private final String message;

    public BaseRuntimeException(Integer code, String message) {
        this(code, message, null);
    }

    public BaseRuntimeException(Integer code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.message = message;
    }

    public BaseRuntimeException(Integer code, String message, Throwable cause,
                         boolean enableSuppression,
                         boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
        this.code = code;
        this.message = message;
    }

    public BaseRuntimeException(ResultCode resultCode) {
        this(resultCode.getCode(), resultCode.getMessage());
    }

    public Integer getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }
}
